<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>掉线处理</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="./../js/index.js"></script>
    <style>
        table {
            word-break: break-all;
            word-wrap: break-word;
            table-layout: auto;
        }

        td {
            width: 10rem;
        }
    </style>
</head>

<body>
    <div class="container">
        <nav class="navbar bg-body-tertiary">
            <form class="container-fluid justify-content-start">
                <button class="btn btn-outline-success me-2 " type="button" onclick="to_demo()">台账</button>
                <button class="btn btn-outline-success me-2 active" type="button">掉线</button>
                <button class="btn btn-outline-success me-2 " type="button" onclick="to_index()">测试</button>
            </form>
        </nav>
    </div>

    <div class="container-sm">
        <h5>处理掉线数据</h5>
        <div class="form-group">
            <textarea class="form-control" rows="3" id="inputinfo1" placeholder="粘贴1-2天掉线车牌"></textarea>
        </div>

        <div class="form-group">
            <textarea class="form-control" rows="3" id="inputinfo2" placeholder="粘贴3天以上掉线车牌"></textarea>
        </div>

        <div class="form-group">
            <textarea class="form-control" rows="3" id="inputinfo3" placeholder="粘贴7天以上掉线车牌"></textarea>
        </div>



        请输入总车辆：<input type="text" id="totalNum">
        <div class="form-group">
            <textarea class="form-control" onclick="copyText(1)" rows="3" id="OnlineSituation"
                placeholder="上线情况"></textarea><span id="cp1" style="font-size: 40px;color: #f20d0d;">复制成功！</span>
        </div>
        监控建议
        <div class="form-group">
            <textarea class="form-control" onclick="copyText(2)" rows="3" id="strf" placeholder="监控建议"></textarea>
        </div>
        <span id="cp2" style="font-size: 40px;color: #f20d0d;">复制成功！</span>

    </div>


    <script>

        var cp1 = document.getElementById("cp1"); //
        cp1.style.display = "none";

        var cp2 = document.getElementById("cp2"); //
        cp2.style.display = "none";

        var num1 = 0
        var num2 = 0
        var num3 = 0


        function joint() {
            num1 = 0
            num2 = 0
            num3 = 0

            var inputinfo1 = document.getElementById("inputinfo1").value
            if (inputinfo1 == null) {

                return false
            }

            if (inputinfo1.indexOf('粤') !== -1) {
                // console.log("包含车牌----------------")

            } else {
                console.log("不包含车牌-------------")

            }

            lines1 = inputinfo1.split(/\r\n|\n/)

            console.log(lines1)


            var result1 = ""

            for (var i = 0; i < lines1.length; i++) {
                if (lines1[i].trim() != "") {
                    result1 = result1 + lines1[i].trim() + ","
                    num1 = num1 + 1
                }
            }
            result1 = result1.substring(0, result1.length - 1);
            console.log("result1======" + result1)

            document.getElementById("inputinfo1").value = ''

            var inputinfo2 = document.getElementById("inputinfo2").value
            if (inputinfo2 == null) {

                return false
            }

            if (inputinfo2.indexOf('粤') !== -1) {
                // console.log("包含车牌----------------")

            } else {
                console.log("不包含车牌-------------")

            }

            lines2 = inputinfo2.split(/\r\n|\n/)

            console.log(lines2)

            var result2 = ""

            for (var i = 0; i < lines2.length; i++) {
                if (lines2[i].trim() != "") {
                    result2 = result2 + lines2[i].trim() + ","
                    num2 = num2 + 1
                }
            }
            result2 = result2.substring(0, result2.length - 1);
            console.log("result2======" + result2)

            document.getElementById("inputinfo2").value = ''


            var inputinfo3 = document.getElementById("inputinfo3").value
            if (inputinfo3 == null) {

                return false
            }

            if (inputinfo3.indexOf('粤') !== -1) {
                // console.log("包含车牌----------------")

            } else {
                console.log("不包含车牌-------------")

            }

            lines3 = inputinfo3.split(/\r\n|\n/)

            console.log(lines3)

            var result3 = ""

            for (var i = 0; i < lines3.length; i++) {
                if (lines3[i].trim() != "") {
                    result3 = result3 + lines3[i].trim() + ","
                    num3 = num3 + 1
                }
            }
            result3 = result3.substring(0, result3.length - 1);
            console.log("result3======" + result3)
            //document.getElementById("inforesult").value = result

            document.getElementById("inputinfo3").value = ''
            var strf = '1、今天掉线的车辆请留意：'
            if (result1 != '') {
                strf = strf + '（' + result1 + '）1-2天未上线；'

            }


            if (result2 != '') {
                strf = strf + '（' + result2 + '）3天以上未上线；'
            }
            if (result3 != '') {
                strf = strf + '（' + result3 + '）7天以上未上线，'
            }
            strf = strf + '请及时留意车辆运作情况进行核实，避免车辆脱离监控。'

            document.getElementById("strf").value = strf



        }




        document.onkeydown = function (e) {
            var ev = document.all ? window.event : e;
            if (ev.keyCode == 13) {
                var cp1 = document.getElementById("cp1"); //
                cp1.style.display = "none";

                var cp2 = document.getElementById("cp2"); //
                cp2.style.display = "none";
                joint()
                online()
            }
        }


        function copyText(flag) {

            var select = ''
            if (flag === 1) {
                select = document.getElementById("OnlineSituation")
                var cp2 = document.getElementById("cp2"); //
                cp2.style.display = "none";
            }

            if (flag === 2) {
                select = strf = document.getElementById("strf")
                var cp1 = document.getElementById("cp1"); //
                cp1.style.display = "none";

            }
            if (select.value === '') {
                return

            }


            select.select(); //选中textarea中的内容
            try {
                var successful = document.execCommand('copy'); //执行复制命令
                if (successful) {
                    console.log('成功复制！');
                    if (flag === 1) {
                        var cp1 = document.getElementById("cp1"); //
                        cp1.style.display = "block";
                    }

                    if (flag === 2) {
                        var cp2 = document.getElementById("cp2"); //
                        cp2.style.display = "block";
                    }

                } else {
                    console.log('无法复制！');
                }
            } catch (err) {
                console.error('无法复制！', err);
            }
        }

        //调用函数进行复制操作
        var textToCopy = '需要复制的文本';
        copyText(textToCopy);


        function online() {

            //
            console.log("num1====" + num1)
            console.log("num2====" + num2)
            console.log("num3====" + num3)
            var totalNum = document.getElementById("totalNum").value
            console.log("9999999999999999999")
            var num = parseInt(totalNum);
            var online = num - parseInt(num1) - parseInt(num2) - parseInt(num3)
            var onlineStr = '当日委托监控的（' + num + '）辆车辆中，共有（' + online + '）辆车当日在线；（' + num1 + '）辆车1-2天未上线、（' + num2 + '）辆车连续3天未上线、（' + num3 + '）辆车连续7天未上线。'

            document.getElementById("OnlineSituation").value = onlineStr
            document.getElementById("totalNum").value = ''


        }



    </script>

    <script src="../js/bootstrap.bundle.min.js"></script>
</body>

</html>